package me.dr0n3.skyAdopt.Listeners;

import java.util.logging.Level;
import me.dr0n3.skyAdopt.Utils.MessageHelper;
import me.dr0n3.skyAdopt.Utils.SignHelper;
import me.dr0n3.skyAdopt.skyAdopt;
import org.bukkit.ChatColor;
import org.bukkit.block.Sign;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.SignChangeEvent;

/**
 * @author dr0n3
 * @date 18.04.2012
 */
public class skyBlockListener implements Listener
{
    skyAdopt plugin;
    
    public skyBlockListener(skyAdopt instance)
    {
        plugin = instance;
    }
    
    @EventHandler
    public void onSignChange(SignChangeEvent e)
    {
        if(skyAdopt.permission.has(e.getPlayer(), skyAdopt.PERM_CREATE) || skyAdopt.permission.has(e.getPlayer(), skyAdopt.PERM_ADMIN))
        {
            if(SignHelper.isValidSkyAdoptSign(e))
            {
                e.setLine(0, ChatColor.BLUE + "[skyAdopt]");
                
                if(SignHelper.isFree(e))
                {
                    e.setLine(2, "free");
                }
            
                MessageHelper.sendMessageToPlayer(e.getPlayer(), "skyAdopt-Schild erstellt.", true);
            }
        }
    }
}
